package com.bitdf.txing.search.controller;

import com.bitdf.txing.common.utils.PageUtils;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.search.service.GroupSearchService;
import com.bitdf.txing.search.to.GroupInfoTo;
import com.bitdf.txing.search.to.GroupOutlineTo;
import com.bitdf.txing.search.to.SearchModelTo;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Lizhiwei
 * @date 2023/1/26 20:06:27
 * 注释：
 */
@RequestMapping("${txing.request.path.search}")
@RestController
@Slf4j
public class GroupSearchController {
    @Autowired
    GroupSearchService groupSearchService;

    @Autowired
    RBloomFilter bloomFilter;

    /**
     * 通过id查询组团
     * @param id
     * @return
     * @throws IOException
     */
    @GetMapping("/group/get/{id}")
    public R getGroupInfoById(@PathVariable("id") Long id) throws IOException {

        GroupInfoTo groupInfoTo=groupSearchService.getGroupById(id);
        return R.ok().put("data", groupInfoTo);
    }


    /**
     * 组团检索
     * @param searchModelTo
     * @return
     * @throws IOException
     */
    @PostMapping("/group/search")
    public R searchGroup(@RequestBody SearchModelTo searchModelTo) throws IOException {

        PageUtils page=groupSearchService.searchGroup(searchModelTo);

        return R.ok().put("data", page);
    }

    /**
     * 获取热点组团信息、排行榜
     * @param size 获取前多少个组团信息
     * @param target 0：获取三个分区热门组团 1：学习区 2：娱乐区 3：生活区 4：获取总的热门组团
     * @return
     */
    @GetMapping("/group/hot")
    public R getallhot(@RequestParam("size") Integer size,@RequestParam("target") Integer target) throws IOException {
        Map<Integer,List<GroupInfoTo>> map=groupSearchService.getHotGroup(size,target);
        return R.ok().put("data", map);
    }

    /**
     * 判断groupId是否合法
     * @param groupId
     * @return
     * @throws IOException
     */
    @GetMapping("/group/is")
    public R isGroupId(@RequestParam("groupId") Long groupId) throws IOException {
        Boolean b=groupSearchService.isGroupId(groupId);
        return b?R.ok():R.error();
    }

    /**
     * 获取群聊简略信息
     * @param groupIds
     * @return
     */
    @PostMapping("/group/simple/get")
    public R getGroupSimpleByGroupIds(@RequestBody Set<Long> groupIds) throws IOException {
        List<GroupOutlineTo> list= groupSearchService.getGroupSimpleByGroupIds(groupIds);
        return R.ok().put("data", list);
    }








}
